home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************/
- /* samples.c modified for in-line resource file using rscfix approach */
- /* C-manship, Listing 1,ST-Log #13,Megamax C.(refined for Mark Williams C)*/
- /**************************************************CJPurcell*11June1987*****/
- #include <OSBIND.H>
- #include <obdefs.h>
- #include <gemdefs.h>
- #include <portab.h>
-
- #include "samples.h" /* The header file from RSC */
- #include "samples.rsh" /* The C source file from RSC */
-
- #define FMD_START 0
- #define FMD_GROW 1
- #define FMD_SHRINK 2
- #define FMD_FINISH 3
- #define R_TREE 0
- #define FINGER 3
-
- /* The usual required GEM global arrays */
- int work_in[11],
- work_out[57],
- pxyarray[10],
- contrl[12],
- intin[128],
- ptsin[128],
- intout[128],
- ptsout[128];
-
- /* Global variables */
- int handle, dum;
-
- int dial_x, /* Dialog x coordinate. */
- dial_y, /* Dialog y coordinate. */
- dial_w, /* Dilaog width. */
- dial_h, /* Dialog height. */
- num, /* Value of number option. */
- n_x, /* NUMBERS object x coord. */
- n_y; /* NUMBERS object y coord. */
-
- char number_str[13] = " 0000 "; /* NUMBERS string. */
-
- char *find_str(); /* Function declaration. */
-
- OBJECT *tree; /* Pointer to an object tree */
-
- /* #include <rscfix.c> / * Code to fixup resource */
- /* RSCFIX.C 09/16/86 Ric Clayton */
- /* STCREATE.c 04/20/85 ATARI */
- /* RSCREATE.C 05/18/84 - 11/01/84 LKW */
- /* Fix something 12/10/84 - 12/10/84 Derek Mui */
- /* Fix the size 12/17/84 */
- /* For ST 04/20/85 Derek Mui */
- /* For code resident rsc 09/16/86 Ric Clayton */
-
- #define adj(xywh, siz) (siz * (xywh & 0x00FF) + (xywh >> 8))
-
- rsc_fix()
- {
- fix_trindex();
- fix_objects();
- fix_tedinfo();
- fix_iconblk();
- fix_bitblk();
- fix_frstr();
- fix_frimg();
- }
-
- fix_trindex()
- {
- int test, ii;
-
- for (ii = 0; ii < NUM_TREE; ii++)
- {
- test = (int) rs_trindex[ii];
- rs_trindex[ii] = (long) &rs_object[test];
- }
- }
-
- fix_objects()
- {
- int test, ii;
- int wchar, hchar;
-
- graf_handle( &wchar, &hchar, &ii, &ii );
-
- for (ii = 0; ii < NUM_OBS; ii++)
- {
- rs_object[ii].ob_x = adj(rs_object[ii].ob_x, wchar);
- rs_object[ii].ob_y = adj(rs_object[ii].ob_y, hchar);
- rs_object[ii].ob_width = adj(rs_object[ii].ob_width, wchar);
- rs_object[ii].ob_height = adj(rs_object[ii].ob_height, hchar);
- test = (int) rs_object[ii].ob_spec;
- switch (rs_object[ii].ob_type) {
- case G_TITLE:
- case G_STRING:
- case G_BUTTON:
- fix_str(&rs_object[ii].ob_spec);
- break;
- case G_TEXT:
- case G_BOXTEXT:
- case G_FTEXT:
- case G_FBOXTEXT:
- if (test != NIL)
- rs_object[ii].ob_spec =
- (char *) &rs_tedinfo[test];
- break;
- case G_ICON:
- if (test != NIL)
- rs_object[ii].ob_spec =
- (char *) &rs_iconblk[test];
- break;
- case G_IMAGE:
- if (test != NIL)
- rs_object[ii].ob_spec =
- (char *) &rs_bitblk[test];
- break;
- default:
- break;
- }
- }
- }
-
- fix_tedinfo()
- {
- int ii;
-
- for (ii = 0; ii < NUM_TI; ii++)
- {
- fix_str(&rs_tedinfo[ii].te_ptext);
- fix_str(&rs_tedinfo[ii].te_ptmplt);
- fix_str(&rs_tedinfo[ii].te_pvalid);
- }
- }
-
- fix_frstr()
- {
- int ii;
-
- for (ii = 0; ii < NUM_FRSTR; ii++)
- fix_str(&rs_frstr[ii]);
- }
-
- fix_str(where)
- long *where;
- {
- if (*where != NIL)
- *where = (long) rs_strings[(int) *where];
- }
-
- fix_iconblk()
- {
- int ii;
-
- for (ii = 0; ii < NUM_IB; ii++)
- {
- fix_img(&rs_iconblk[ii].ib_pmask);
- fix_img(&rs_iconblk[ii].ib_pdata);
- fix_str(&rs_iconblk[ii].ib_ptext);
- }
- }
-
- fix_bitblk()
- {
- int ii;
-
- for (ii = 0; ii < NUM_BB; ii++)
- fix_img(&rs_bitblk[ii].bi_pdata);
- }
-
- fix_frimg()
- {
- int ii;
-
- for (ii = 0; ii < NUM_FRIMG; ii++)
- fix_bb(&rs_frimg[ii]);
- }
-
- fix_bb(where)
- long *where;
- {
- if (*where != NIL)
- *where = (long) (char *) &rs_bitblk[(char) *where];
- }
-
- fix_img(where)
- long *where;
- {
- if (*where != NIL)
- *where = (long) (char *) rs_imdope[(int) *where].image;
- }
-
- #undef adj
-
-
- main()
- {
- appl_init (); /* Initialize application. */
- open_vwork (); /* Set up workstation. */
- rsc_fix(); /* recreate resource file in-line */
- do_dialog(SAMPLE,OK); /* Go do the dialog box. */
- /* print_results(tree_addr); / * Print user's choices. */
- button_wait(); /* Wait for mouse button. */
- v_clsvwk (handle); /* Close virtual workstation. */
- appl_exit (); /* Back to the desktop. */
- }
-
- open_vwork ()
- {
- int i;
-
- /* Get graphics handle, initialize the GEM arrays and open */
- /* a virtual workstation. */
-
- handle = graf_handle (&dum,&dum,&dum,&dum);
- for (i=0; i<10; work_in[i++] = 1);
- work_in[10] = 2;
- v_opnvwk (work_in, &handle, work_out);
- }
-
- do_dialog ( rsc_tree , exit_obj)
- int rsc_tree;
- int exit_obj;
- {
- int choice; /* Button choice from dialog. */
-
- /* Here we load the resource file. If the file is missing, */
- /* we warn the user with an alert box then terminate the */
- /* program by skipping the code following the else. */
- /* if (! rsrc_load ("\SAMPLE.RSC"))
- form_alert (1, "[1][SAMPLE.RSC missing!][I'll do better!]"); */
- /* If the resource file loads OK, we get the address of the */
- /* tree, get the coords for centering the dialog, save the */
- /* portion of the screen that'll be covered by the dialog, */
- /* and draw the dialog. The mouse pointer is changed to */
- /* pointing finger. */
- /* else { */
- /* rsrc_gaddr (R_TREE, SAMPLE, &tree_addr); */
-
- tree = (OBJECT *) rs_trindex[ rsc_tree ];
- form_center (tree, &dial_x, &dial_y, &dial_w, &dial_h);
- objc_offset (tree, NUMBERS, &n_x, &n_y);
- form_dial (FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h);
- form_dial (FMD_GROW, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h);
- objc_draw (tree, 0, 2, dial_x, dial_y, dial_w, dial_h);
- graf_mouse (FINGER,&dum);
-
- /* Here we allow the user to interact with the dialog then, */
- /* based on the chosen button, perform the necessary action. */
- /* The form_do function is repeated until the user chooses */
- /* either the OK button or the CANCEL button. */
-
- num = 0;
- do {
- choice = form_do (tree, YOURNAME);
- if (choice == RADIO1) v_gtext (handle,160,20,"Radio 1 ");
- if (choice == RADIO2) v_gtext (handle,160,20,"Radio 2 ");
- if (choice == RADIO3) v_gtext (handle,160,20,"Radio 3 ");
- if (choice == RADIO4) v_gtext (handle,160,20,"Radio 4 ");
- if (choice == RADIO5) v_gtext (handle,160,20,"Radio 5 ");
- if (choice == RADIO6) v_gtext (handle,160,20,"Radio 6 ");
- if (choice == OPTION1) v_gtext (handle,160,20,"Option 1 ");
- if (choice == OPTION2) v_gtext (handle,160,20,"Option 2 ");
- if (choice == UPARO) do_up();
- if (choice == DNARO) do_down();
- }
- while (choice != CANCEL && choice != exit_obj);
-
- /* Once the CANCEL or OK buttons have been pressed, we clean */
- /* up after ourselves by performing the "shrinking box" and */
- /* then redrawing the screen. */
-
- form_dial (FMD_SHRINK, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h);
- form_dial (FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h);
- print_results(); /* Print user's choices. */
- }
-
- do_up ()
- {
-
- /* First we increment our value and make sure it stays in */
- /* range. If the value has become larger than 9999, we must */
- /* also reinitialize display string for the object NUMBERS. */
- /* We then call our function to update the NUMBERS object. */
-
- num += 1;
- if (num > 9999) {
- num = 0;
- strcpy (number_str," 0000 ");
- }
- edit_object ();
- }
-
- do_down ()
- {
-
- /* Here we decrement the value and check for its range, after */
- /* which we update the NUMBERS object. */
-
- num -= 1;
- if (num < 0) num = 9999;
- edit_object ();
- }
-
- edit_object ()
- {
- TEDINFO *ob_tedinfo;
- char temp_str[10];
-
- /* Here we edit the string we're using for the text display */
- /* in the object NUMBERS so that it reflects the new value. */
-
- sprintf (temp_str,"%d",num);
- strcpy (&number_str[8 - strlen (temp_str)],temp_str);
- strcpy (&number_str[8]," ");
-
- /* Then we find the object NUMBERS' TEDINFO and point the */
- /* te_ptext member to our updated string, after which we */
- /* redraw the object NUMBERS. */
-
- ob_tedinfo = (TEDINFO *) tree[NUMBERS].ob_spec;
- ob_tedinfo -> te_ptext = number_str;
- objc_draw (tree, NUMBERS, 1, n_x, n_y, 96, 16);
- }
-
- print_results()
- {
- char *string;
-
- /* Here we call the function that locates the string, then */
- /* print the user's input to the screen. */
-
- string = find_str (YOURNAME, string);
- v_gtext (handle, 160, 20, "Your name is ");
- v_gtext (handle,264,20,string);
- string = find_str (AGE, string);
- v_gtext (handle, 160, 28, "Your age is ");
- v_gtext (handle, 264, 28, string);
- string = find_str (NUMBERS, string);
- v_gtext (handle, 160, 36, "Final number value: ");
- v_gtext (handle,320,36,&string[4]);
- }
-
- char *find_str (object, string)
- int object;
- char *string;
- {
- TEDINFO *ob_tedinfo;
-
- /* In this function, we locate the object's TEDINFO structure */
- /* then set our string pointer to the pointer found in the */
- /* te_ptext member. */
-
- ob_tedinfo = (TEDINFO *) tree[object].ob_spec;
- string = ob_tedinfo -> te_ptext;
- return (string);
- }
-
- /* Waits for left button to be pressed and released. */
- button_wait()
- {
- evnt_button (1,1,1,&dum,&dum,&dum,&dum);
- evnt_button (1,1,0,&dum,&dum,&dum,&dum);
- }
- /*
- void sort(v,n)
- char *v[];
- int n;
- {
- .
- .
- }
- .
- .
- .
- void do_form( rsc_tree, exit_obj )
- int rsc_tree;
- int exit_obj;
- {
- int xdial, ydial, wdial, hdial;
- int x, y, w, h;
- int object;
-
- tree = (OBJECT *) rs_trindex[ rsc_tree ];
-
- form_center( tree, &xdial, &ydial, &wdial, &hdial );
- x = xdial + wdial/2;
- y = ydial + hdial/2;
- w = gl_wbox;
- h = gl_hbox;
- form_dial( 0, x, y, w, h, xdial, ydial, wdial, hdial );
- form_dial( 1, x, y, w, h, xdial, ydial, wdial, hdial );
-
- objc_draw( tree, ROOT, MAX_DEPTH, xdial, ydial, wdial, hdial );
-
- object = 0;
-
- while( object != exit_obj )
- {
- object = form_do( tree, 0 ) & 0x7FFF;
- handle_object( tree, object );
- .
- .
- .
- }
-
- form_dial( 2, x, y, w, h, xdial, ydial, wdial, hdial );
- form_dial( 3, x, y, w, h, xdial, ydial, wdial, hdial );
- }
-
- main()
- {
- if ( appl_init() >= 0 )
- {
- rsc_fix();
- .
- .
- graf_mouse( M_ON, 0x0L );
- graf_mouse( ARROW, 0x0L );
- do_form( TREE0, OKBUTTON );
- .
- .
- appl_exit();
- }
- }
- */
-